﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Hot.aspx.cs" Inherits="Hot" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Hot</title>
    <link href="css/baseline.css" rel="stylesheet" media="screen, projection" type="text/css" />
    <link href="css/print.css" rel="stylesheet" media="print" type="text/css" />

    <script src="js/jquery-1.3.2.js" type="text/javascript"></script>

    <style type="text/css">
        html
        {
	        overflow-x: hidden;
        } 
        body
        {
            background: #fff;
            margin-top: 0px;
        }

    
    </style>

    <script type="text/javascript">
    
        var u='<%=Session["uid"].ToString() %>';

        $().ready(function() {
             InitData(0,8,"votes");
                     
        });
        
        function pageselectCallback(page_id, jq) {
            InitData(page_id,8,"votes");
        }
        
        function join(iid) {
            location.href = "Join.aspx?i=0&IID=" + iid;
        }
        
        function InitData(pageindx,pagesize,type)
        {
            var div = "";
           
            $.ajax({
               type: "POST",//用POST方式传输
               dataType:"json",//数据格式:JSON
               url:'handler.ashx',//目标地址
               data:"p="+(pageindx+1)+"&s="+pagesize+"&cate="+type+"&u="+u,
               beforeSend:function(){},//发送数据之前 $("#divload").show();$("#Pagination").hide();
               complete:function(){},//接收数据完毕$("#divload").hide();$("#Pagination").show()
               success:function(json) {
                    $("#latest li").remove();    
                    var ideaData = json.Ideas;
                    var joined = false;
                    var voted = false;
                    $.each(ideaData, function(i, n) {
                        var trs = "";
                        trs +="<li>";
                        
                        trs +="<div class=\"idea\">";
                        trs +="<div class=\"i_left\">";
                        trs +="<h5>" + n.CategoryType + "</h5>";
                        trs +="<a href=\"CurrentIdea.aspx?i=0&IID=" + n.IID + "\" class=\"title\" >" + n.Title + "</a>";
                        switch(n.State)
                        {
                            case '1':
                                trs +="<img src=\"images/new.gif\" />";
                                break;
                            case '2':
                                trs +="<img src=\"images/beingreviewed.gif\" />";
                                break;
                            case '3':
                                trs +="<img src=\"images/returned.gif\" />";
                                break;
                            case '4':
                                trs +="<img src=\"images/beingimplemented.gif\" />";
                                break;
                        }
                        trs +="<div class=\"bottom\"> Posted By <a href=\"http://www.colleaguefinder.com/EmployeeProfile.htm?employeeId=" + n.CreatedBy + "\" class=\"username\" target=\"_blank\" >" + n.LastName + ", " + n.FirstName + "</a> at " + n.CreatedTime + " <a href=\"CurrentIdea.aspx?i=0&IID=" + n.IID + "\" class=\"comments\"> (" + n.CommentNum + " Comments)</a></div>";
                        trs +="</div>";
                        trs +="<div class=\"i_right\">";
                        var types = n.MapTypes.split('|');
                        joined = false;
                        voted = false;
                        for(var j=0;j<types.length;j++)
                        {
                            if(types[j] == 1) joined = true;
                            if(types[j] == 2) voted = true;
                        }
                        
                        if(!joined)
                        {
                            trs +="<img src=\"images/join-button.gif\" class=\"image\" title=\"contribute to this idea\" alt=\"contribute to this idea\" onclick=\"javascript:join(" + n.IID + ");\" />";
                        
                        }
                        else
                        {
                            trs +="<img src=\"images/join-button-gray.gif\" class=\"image\" title=\"you've already joined\" alt=\"you've already joined\" />";
                        }
                        if(!voted)
                        {
                            trs +="<img src=\"images/vote-button.gif\" class=\"image\" title=\"vote\" alt=\"vote\" onclick=\"javascript:voteForLike('" + u + "'," + n.IID + ")\" id=\"link_" + n.IID + "\" />";
                        }
                        else
                        {
                            trs +="<img src=\"images/vote-button-gray.gif\" class=\"image\" title=\"you've already voted.\" alt=\"you've already voted.\" />";
                        }
                        trs +="<label class=\"num\" title=\"votes\" id=\"vote_" + n.IID + "\" > (" + n.Votes + ") </label>";

                        trs +="</div>";
                        trs +="</div>";
                       
                        trs +="</li>";
                        
                        div += trs;
                    });

                    $("#latest").append(div);
                }});
            
        }
        
        var voteForLike=function(uid,iid)
        {
           $.ajax({
           type: "POST",//用POST方式传输
           dataType:"json",//数据格式:JSON
           url:'vote.ashx',//目标地址
           data:"IID="+iid+"&UID="+uid,
           beforeSend:function(){ },//发送数据之前
           complete:function(){ },//接收数据完毕
           success:function(json) {   
                    var resultData = json.Result;
                    if( resultData >= 1)
                    {
                        //$("#link_" + iid).remove();
                        $("#link_" + iid).attr("onclick","");
                        $("#link_" + iid).attr("src","images/vote-button-gray.gif");
                        $("#link_" + iid).attr("title","you've already voted.");
                        $("#link_" + iid).attr("alt","you've already voted.");
                        $("#vote_" + iid).html("(" + resultData + ")");
                    }
                        
            }});
        }

        
    </script>

</head>
<body>
    <form id="form1" runat="server">
        <asp:Label ID="Emptylbl" runat="server"></asp:Label>
        <div class="idealist">
            <ul id="latest">
            </ul>
        </div>
    </form>
</body>
</html>
